package day06;

import java.util.Arrays;
import java.util.Random;

//方法的演示
public class MethodDemo {
    public static void main(String[] args) {
        say();//调用say()方法
        System.out.println("继续执行------");
        System.out.println("----------------");

        say("张三",21);
        System.out.println("------------------");

        int a = sum(5,8);
        System.out.println(a);
        System.out.println("------------------");

        int n = 10,m=123;
        int b = sum1(n,m);
        System.out.println(b);
        System.out.println("--------------------");

        int[] arr = generateArray(5,20);
        System.out.println(arr.length);
        //System.out.println(arr[0]);
        System.out.println("-----------");

        int[] arr1 = generateArray(10,50);
        bianYi(arr);
        System.out.println("第一个数是:"+arr1[0]);
        Arrays.sort(arr1);
        System.out.println("排序后:");
        bianYi(arr1);


    }


    //无参数无返回值
    public  static  void  say(){
        System.out.println("大家好啊,你们吃饭了吗?");
    }
    //有参数无返回值
    public static void say(String name,int age){
        System.out.println("大家好,我叫"+name +", 今年"+age+"岁了");
    }
    //有参数有返回值
    public static int sum(int sum1,int sum2){
        int sum = sum1+sum2;
        return sum;
    }
    public static int sum1(int sum1,int sum2){
        return sum1+sum2;
    }
    public static int[] generateArray(int len,int max){
        Random ran = new Random();
        int[] arr = new int[len];
        for (int i =0;i<arr.length;i++){
            arr[i] = ran.nextInt(max+1);
        }
        return arr;
    }
    public static void bianYi(int[] a){
        for (int i =0;i<a.length;i++){
            System.out.println(a[i]);
        }
    }
    public static void say(int age){}//编译正确
    public static void say(int sum1,String name ){}//编译正确
    //public static int say(){ return 1;} //编译错误,跟返回值的类型无关
    //public static void say(String address,int age){}//编译错误,重载与返回值的名字无关
}
